// main.cpp
// QuadraticFunction class demonstration after separating its interface from its implementation
#include <iostream> // allows program to perform input and output
#include "QuadraticFunction.h" // include definition of class QuadraticFunction
using namespace std; // program uses names from the std namespace

// function main begins program execution
int main()
{
	// variable declarations
	double quadraticTerm;	// constant of the quadratic term
	double linearTerm;		// constant of the linear term
	double constantTerm;	// constant of the constant term
	bool quit = false;		// quit indicator
	char option;			// user's choice of option

	// display welcome message:
	cout << "Welcome to the Quadratic Function Tool!\n";
	cout << "Please start by entering a quadratic function.\n\n";

	// prompt user for the constants and get each input
	cout << "Enter the constant value for the quadratic term: ";
	cin >> quadraticTerm;
	cout << "Enter the constant value for the linear term: ";
	cin >> linearTerm;
	cout << "Enter the constant value for the constant term: "; 
	cin >> constantTerm;

	// create QuadraticFunction object named myQuadFunction
	QuadraticFunction myQuadFunction( quadraticTerm, linearTerm, constantTerm );

	while (!quit)
	{
		cout << "\nContinue? (Yes=Y, No=N): "; // prompt user to continue
		cin >> option;

		if ( option == 'N' || option == 'n' )
			break; // break do...while loop only if user decides to quit

		// display Menu options to the user
		cout << "\nMain Menu:\n";
		cout << "(1) Display the "<<myQuadFunction.equationType<<" Function" << endl;
                        if (myQuadFunction.equationType=="Quadratic")
                                {cout << "(2) Compute the Discriminant" << endl;
                                cout << "(3) Use the Quadratic Formula to find its solutions" << endl;}
                        if (myQuadFunction.equationType=="Linear")
                                {cout <<"(3) Find the y-intercept"<<endl;}
		cout << "(4) Create XY table for the "<<myQuadFunction.equationType<<" Function" << endl;
		cout << "(5) New Quadratic Function" << endl;
		cout << "(6) Quit" << endl << endl;
		// prompt user to pick an option from the menu
		cout << "What do you want to do? ";
		cin >> option;
		
		switch ( static_cast<int> (option) ) // switch statement nested in do...while
		{
		case 49: myQuadFunction.displayFunction(); // call object's displayFunction()
			break;
		case 50: // call object's computeDiscriminant() and display discriminant
                    if (myQuadFunction.equationType=="Quadratic")
                    {	cout << "The Discriminant for this quadratic equation is: ";
			cout << myQuadFunction.computeDiscriminant() << endl << endl;}
			break;
		case 51: 
                    if(myQuadFunction.equationType=="Quadratic"| myQuadFunction.equationType=="Linear")
                    { myQuadFunction.determineSolution();} // call object's determineSolution()
			break;
		case 52: myQuadFunction.createTableXY(); // call object's createTableXY()
			break;
		case 53: cout << "Enter the constant value for the quadratic term: ";
			cin >> quadraticTerm;
			cout << "Enter the constant value for the linear term: ";
			cin >> linearTerm;
			cout << "Enter the constant value for the constant term: "; 
			cin >> constantTerm;
			myQuadFunction.setConstants( quadraticTerm, linearTerm, constantTerm );
			break;
		case 54: quit = true; // set the quit indicator
			break;
		default: cout << "Invalid entry!\n";
			break;
		}
	}

	return 0; // indicate program ended successfully
} // end main